package org.smarthings.things.management.impl;

import java.util.Collections;
import java.util.List;

import org.smarthings.things.management.Thing;
import org.smarthings.things.management.ThingAction;
import org.smarthings.things.management.ThingActionCollection;

public class ThingActionCollectionImpl implements ThingActionCollection {

	private List<ThingAction> actions;

	public ThingActionCollectionImpl(List<ThingAction> actions) {
		this.actions = Collections.unmodifiableList(actions);
	}

	@Override
	public ThingAction getActionByUUID(String actionUUID) {
		for (ThingAction action : actions) {
			if (actionUUID.equals(action.getUUID())) {
				return action;
			}
		}
		return null;
	}

	@Override
	public ThingAction getActionByType(String actionType) {
		for (ThingAction action : actions) {
			if (actionType.equals(action.getType())) {
				return action;
			}
		}
		return null;
	}

	@Override
	public List<ThingAction> listActions() {
		return actions;
	}

	void bindThing(Thing thing) {
		for (ThingAction action : actions) {
			ThingActionImpl implaction = (ThingActionImpl) action;
			implaction.bindThing(thing);
		}
	}

}
